有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

selenium中的java用户登录身份验证?

我在excel工作表中有一个usernamepassword的列表

我正在尝试查找登录页的有效用户凭据

这是我的代码:

Workbook wBook = null;
try {
    wBook = Workbook.getWorkbook(new File("C:/Users/jayant.gupta/Desktop/Book1.xls"));
} catch (BiffException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
//get sheet
jxl.Sheet s = wBook.getSheet(0); 

for(int i=0;i<s.getRows();i++)
 {
   for(int j=0;j<s.getColumns();j++)
   {
         Cell cell=s.getCell(j, i);
         System.out.println("     "+cell.getContents());
         System.out.println("i "+i);
         System.out.println("j "+j);
         if(j==0){
             driver.findElement(By.id("textBoxUserName")).sendKeys(cell.getContents());
         }
         if(j==1){
            driver.findElement(By.id("txtPswd")).sendKeys(cell.getContents());
            driver.findElement(By.id("explore")).click();
            driver.findElement(By.id("textBoxUserName")).clear();
            driver.findElement(By.id("txtPswd")).clear();

         }       
   }
   System.out.println("\n");
 }

我在excel中总共有6个登录凭据。从中只有1个是有效凭证,位于excel的位置4

当我到达excel的第四个位置时,它会将我带到下一页

但是我想检查下两个登录凭据是否有效

我该怎么做


共 (1) 个答案

  1. # 1 楼答案

    • 使用parametrized tests而不是迭代
    • 为每个测试创建新的webdriver实例,这样您就不必担心是否登录了